export const ActionTypes = {
  change: 'detail_change',
  del: 'detail_del',
  init: 'detail_init'
}

export function initUser() {
  return (dispatch, getState)=>{
    setTimeout(() => {
      const user = {
        name:'张三',
        id: '123456'
      }
      dispatch({
        type: ActionTypes.init,
        user
      })
    }, 200);
  }
}

const initstate = {
  name: '',
  id: ''
} 

const reducer = (state = initstate, action) => {
  console.log('reducer')
  switch (action.type) {
    case ActionTypes.change:
      return {
        ...state,
        ...action.user
      }
    case ActionTypes.del:
      return {
        name: '',
        id: ''
      }
      case ActionTypes.init:
        return action.user
    default: 
      return state
  }
}

export default reducer
